<!doctype html>
<html class="no-js">

<head>
    <title>添加库存</title>
    <#include "/boya/template/meta.html" />
</head>

<body>
    <div id="app" class="page">
        <form class="layui-form" action="">
            <!-- <div class="layui-form-item">
                <label class="layui-form-label">入库单位</label>
                <div class="layui-input-block">
                    <el-select v-model="schoolId" filterable placeholder="入库单位">
                        <el-option v-for="item in schools" :key="item.attrs.id" :label="item.attrs.name" :value="item.attrs.id">
                        </el-option>
                    </el-select>
                </div>
            </div> -->
            <div class="layui-form-item">
                <label class="layui-form-label">物品类别</label>
                <div class="layui-input-block">
                    <input type="text" lay-verify="" placeholder="请输入物品类别" autocomplete="off" class="layui-input" v-model="category">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">物品名称 <span style="color: red;">*</span></label>
                <div class="layui-input-block">
                    <input type="text" required lay-verify="" placeholder="请输入物品名称" autocomplete="off" class="layui-input" v-model="name">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">分类</label>
                <div class="layui-input-block">
                    <input type="text" lay-verify="" placeholder="请输入分类" autocomplete="off" class="layui-input" v-model="type">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">型号</label>
                <div class="layui-input-block">
                    <input type="text" lay-verify="" placeholder="请输入型号" autocomplete="off" class="layui-input" v-model="size">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">数量 <span style="color: red;">*</span></label>
                <div class="layui-input-block">
                    <input type="number" required lay-verify="" placeholder="请输入数量" autocomplete="off" class="layui-input" v-model="count">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <input type="text" lay-verify="" placeholder="请输入备注" autocomplete="off" class="layui-input" v-model="remark">
                </div>
            </div>
        </form>
        <div style="margin-left: 110px;">
            <button class="am-btn am-btn-primary" @click="submit">提交</button>
        </div>
    </div>
    <#include "/boya/template/script.html" />
    <script type="text/javascript">
    var app = new Vue({
        el: '#app',
        data() {
            return {
                pageIndex: parent.layer.getFrameIndex(window.name),
                categorySelection: [],
                // schools: [],
                editable: true,
                id: '',
                // schoolId: '',
                category: '',
                name: '',
                type: '',
                size: '',
                count: '',
                remark: ''
            }
        },
        mounted: function() {
            var self = this;
            var jsonStr = '${info!}';
            if (jsonStr != '') {
                var info = JSON.parse(jsonStr);
                this.id = info.id;
                // this.schoolId = info.schoolId;
                this.category = info.category;
                this.name = info.name;
                this.type = info.type;
                this.size = info.size;
                this.count = info.count;
                this.remark = info.remark;

                self.editable = false;
            }
            // <#--var schoolStr = '${schools!}';
            // if (schoolStr != '') {
            //     this.schools = ${schools!'[]'}-->
            // }
        },
        methods: {
            submit() {
                var self = this;
                var _parent = parent;
                // if (self.schoolId == '') {
                //     msg("请选择入库单位");
                //     return;
                // }
                if (self.name == '') {
                    msg("请输入名称");
                    return;
                }
                if (self.count == '') {
                    msg("请输入数量");
                    return;
                }
                if (Number(self.count) < 0) {
                    msg("数量不能为负数");
                    return;
                }
                var map = {
                    // schoolId: self.schoolId,
                    category: self.category,
                    name: self.name,
                    type: self.type,
                    size: self.size,
                    count: self.count,
                    remark: self.remark
                }
                if (self.id != '') {
                    map['id'] = self.id;
                }
                var param = Qs.stringify(map);
                axios({
                        url: '/boya/submitStock',
                        method: 'post',
                        data: param,
                        headers: {
                            'Content-Type': 'application/x-www-form-urlencoded'
                        }
                    })
                    .then(function(response) {
                        console.log(response);
                        if (response.data.status == 200) {
                            // _parent.msg("保存成功");
                            // _parent.layer.close(self.pageIndex);
                            _parent.window.location.reload();
                        } else {
                            _parent.msg("保存失败");
                            _parent.layer.close(self.pageIndex);
                            console.log(response.data);
                        }
                    })
                    .catch(function(error) {
                        _parent.msg("保存失败");
                        _parent.layer.close(self.pageIndex);
                        console.log(error);
                    });
            }
        }
    })
    </script>
    <style type="text/css">
    .page {
        padding: 15px;
    }

    .layui-form-label {
        width: 100px;
    }

    .submit-wrap {
        text-align: center;
    }
    </style>
</body>

</html>